package feng.demo.controller.mer;

import cn.dev33.satoken.stp.StpUtil;
import feng.demo.entity.Commodity;
import feng.demo.entity.Remark;
import feng.demo.entity.User;
import feng.demo.entity.XJson;
import feng.demo.service.CommodityService;
import feng.demo.service.RemarkService;
import feng.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mer/remark")
public class MerRemarkController {

    @Autowired
    CommodityService commodityService;
    @Autowired
    RemarkService remarkService;
    @Autowired
    UserService userService;
    @GetMapping("/findAll/{p}/{l}")
    public String findAll(@PathVariable("p")Integer p,@PathVariable("l")Integer l){
        Object phone = StpUtil.getLoginId();
        User user = userService.findByPhone(String.valueOf(phone));
        List<Commodity> remark = commodityService.findRemark(user.getUid(), p, l);
        int count = commodityService.CountByUid(user.getUid());
        Map<String,Object> map =new HashMap<>();
        map.put("remark",remark);
        map.put("count",count);
        return new XJson(200,"",map).toString();
    }


}
